home *** CD-ROM | disk | FTP | other *** search
- /* File: ControlKeyPatch.h
-
- Description:
- routines for patching the ADB manager to simulate the control
- key being held down. This file contains declarations for routines
- in ControlKeyPatch.c. These routines are for installing,
- removing and calling the control key patch.
-
- Author: John Montbriand
-
- Copyright:
- Copyright © 1999 by Apple Computer, Inc.
- All rights reserved worldwide.
-
- Disclaimer:
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- Change History (most recent first):
- 27/8/99 created by John Montbriand
- */
-
- #ifndef __CONTROLKEYPATCH__
- #define __CONTROLKEYPATCH__
-
- #include <MacTypes.h>
- #include <DeskBus.h>
- #include <MixedMode.h>
-
- /* layout of the patch segment data */
- #pragma options align=mac68k
- typedef struct {
- short branch; /* bra.s instruction to ADB service routine */
- short downbranch; /* bra.s instruction to routine for pressing key */
- short upbranch; /* bra.s instruction to routine for releasing key */
- long codedata[1]; /* remaining instructions making up segment */
- } ControlKeyPatchSegment;
- #pragma options align=reset
-
-
- /* data variables used for storing information about the patch */
-
- typedef struct ControlKeyPatchVars ControlKeyPatchVars;
- typedef ControlKeyPatchVars *ControlKeyPatchPtr;
-
-
- /* definitions used for calling back to the segment. They allow these
- calls to be made from 68k or powerpc code. */
-
- typedef void (*KeyCmdCallPtr)(ControlKeyPatchPtr data);
-
- #if TARGET_CPU_PPC
- typedef UniversalProcPtr KeyCmdCallUPP;
- enum {
- uppControlKeyCommandProcInfo = kCStackBased
- | RESULT_SIZE(kNoByteCode)
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ControlKeyPatchPtr)))
- };
- #define NewControlKeyCommandUPP(theProc) NewRoutineDescriptor((ProcPtr) (theProc), uppControlKeyCommandProcInfo, kM68kISA)
- #define DisposeControlKeyCommandUPP(theProc) DisposeRoutineDescriptor((UniversalProcPtr) (theProc))
- #define CallControlKeyCommandUPP(theProc, data) CallUniversalProc((UniversalProcPtr) theProc, uppControlKeyCommandProcInfo, data)
- #else
- typedef KeyCmdCallPtr KeyCmdCallUPP;
- #define NewControlKeyCommandUPP(theProc) ((KeyCmdCallUPP)(theProc))
- #define DisposeControlKeyCommandUPP(theProc)
- #define CallControlKeyCommandUPP(theProc, data) ((KeyCmdCallUPP) (theProc))(data)
- #endif
-
- struct ControlKeyPatchVars {
- /* fields shared by the assembly code and the C code.
- Their offests in this structure are important as they
- are assumed by the 68k assembly. */
- long command;
- long downflag;
- long originaljump;
- long originaldata;
- /* for restoring the previous adb state */
- ADBAddress adbAddress;
- /* the code segment and its variables */
- ControlKeyPatchSegment *patchSegment;
- /* for calling back to the patch */
- KeyCmdCallUPP SetKeyUpHook;
- KeyCmdCallUPP SetKeyDownHook;
- /* for tracking the heap */
- long systemPatch;
- };
-
- /* kErrNoKeyboardFound is returned by NewControlKeyPatch
- or ControlKeyPatchReInstall when no keyboard can be found. */
- enum {
- kErrNoKeyboardFound = 1324
- };
-
- /* NewControlKeyPatch installs a new patch for the control key and returns
- a structure that can be used for calling and maintaining the patch. If inSysHeap
- is true, then the patch and all of it's related structures are allocated in the
- system heap. Normally, patches should be allocated in the system heap
- unless it is being allocated for testing purposes. */
- OSErr NewControlKeyPatch(Boolean inSysHeap, ControlKeyPatchPtr *patch);
-
- /* DisposeControlKeyPatch removes the patch and disposes of all of the structures
- associated with it. normally, you'll never call this routine, unless you're using
- the patch locally in an application. */
- void DisposeControlKeyPatch(ControlKeyPatchPtr patch);
-
- /* ControlKeyPatchReInstall should be called when the ADB table has been
- re-initialized. Normally, you'll call this routine from a patch to the
- _ADBReInit trap. */
- OSErr ControlKeyPatchReInstall(ControlKeyPatchPtr patch);
-
- /* SetControlKeyDown can be called to lock down the control key. While the
- key is locked down, the control key is turned off on the keyboard. It is safe
- to call this routine at interrupt time.*/
- void SetControlKeyDown(ControlKeyPatchPtr patch);
-
- /* SetControlKeyUp should be called after a call to SetControlKeyDown.
- this routine unlocks the control key. It is safe to call this routine
- at interrupt time. */
- void SetControlKeyUp(ControlKeyPatchPtr patch);
-
-
-
- #endif
-